<template>
  <div class="fullscreen-content" @click="reGenMenus">
    <Icon width="24px" icon="material-symbols:refresh" />
  </div>
</template>

<script setup lang="ts">
import useMenuStore from "@/store/modules/menus";
import { Icon } from "@iconify/vue";
import { ref, onMounted } from "vue";
import { generateMenu } from "./GenerateMenu";
import { PracticeItem } from "./GenerateMenu";
import addDynamicRoute from "./GenerateRoutes";
import { RouteRecordRaw, useRouter } from "vue-router";

const menus = useMenuStore();

const router = useRouter();
const practices = ref<PracticeItem>({
  name: "/",
  path: "/",
  title: "root",
  children: []
});

onMounted(() => {
  reGenMenus();
});

const reGenMenus = async () => {
  practices.value = generateMenu();
  menus.set(practices.value);
  const routes: Array<RouteRecordRaw> = addDynamicRoute(practices.value);
  routes.forEach(async route => {
    await router.addRoute(route);
  });
};
</script>

<style scoped>
.fullscreen-content {
  width: 40px;
  height: 100%;
  /* margin-right: 10px; */
  /* background-color: #f0f0f0; */
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  icon {
    font-weight: 600;
    width: 52px;
    height: 52px;
  }
}
.fullscreen-content:hover {
  background-color: var(--el-color-primary-light-9);
}
</style>
